// function name1 <T> (user:T): T {
//     return user
// }
// name1 ("zs")

// interface HasLength {
//     length: number;
//   }
  
//   function getLength<T extends HasLength>(arg: T): number {
//     return arg.length; 
//   }
//   getLength("hello");
function mapArray<T, U>(arr: T[], callback: (item: T) => U): U[] {
    return arr.map(callback);
  }
  const numbers = [1, 2, 3];
  const strings = mapArray(numbers, (n) => n.toString());
  console.log(strings); 
interface Box<T> {
    name3: T;
    data:number
  }
  
//   // 使用示例
//   const stringBox: Box<string> = {
//     name3: "zs"
//   };
  
//   const numberBox: Box<number> = {
//     name3: 123
//   };

//   type AgeObject = {
//     age: number;
// };
type Person = {
    name: string;
    age: number;
};
const personBox: Box<Person> = {
    name3: {
        name: "z",
        age: 12
    },
    data: 300
};
const www: Box<{name: string, data: number}> = {
    name3: {
        name: "z",
        data: 12
    },
    data: 400
};
// ‌Partial<T>‌ - 将所有属性变为可选，常用于对象的部分更新场景
interface User { id: number; name: string; }
type PartialUser = Partial<User>; // { id?: number; name?: string; }
// ‌Required<T>‌ - 将所有属性变为必选，与Partial作用相反
type OptionalUser = { id?: number; name?: string; };
type RequiredUser = Required<OptionalUser>; // { id: number; name: string; }
// ‌Readonly<T>‌ - 使所有属性变为只读，创建不可变对象
interface Config { apiUrl: string; timeout: number; }
type ImmutableConfig = Readonly<Config>; // { readonly apiUrl: string; readonly timeout: number; }
// ‌Pick<T, K>‌ - 从类型中选取指定属性
interface User { id: number; name: string; age: number; }
type BasicInfo = Pick<User, "id" | "name">; // { id: number; name: string; }
// Omit<T, K>‌ - 从类型中排除指定属性
type UserWithoutAge = Omit<User, "age">; // { id: number; name: string; }
// Record<K, T>‌ - 创建键值对对象类型，适用于配置映射
type UserRoles = "admin" | "user";
type RolePermissions = Record<UserRoles, boolean>; // { admin: boolean; user: boolean; }
// ‌ReturnType<T>‌ - 获取函数返回类型，特别实用
function getUser() { return { name: "John", age: 25 }; }
type UserData = ReturnType<typeof getUser>; // { name: string; age: number; }
// ‌Exclude<T, U>‌ - 从联合类型中排除特定类型
type T = string | number | boolean;
type NumericOrBoolean = Exclude<T, string>; // number | boolean
// ‌Awaited<T>‌ - 解包Promise类型，获取实际解析值
type PromiseResult = Awaited<Promise<string>>; // string


